from Locators.PersonalcodeLocators.personalcode_locators import PersonalcodeLocator as loc
from Common.plugs.basepage import BasePage
import time
import allure


class PersonalcodePage(BasePage):

    def add_code(self, codeName: str, img: str):
        doc = '员工活码列表页面_新增活码'
        '''
        用例描述：
        前置：登陆，进去员工活码页面
        '''
        with allure.step("step：点击新增"):
            self.click_element(loc.code_add_btn, doc)
        with allure.step("step：输入活码名称"):
            self.input_element(loc.code_add_name, codeName, doc)
        with allure.step("step：选择渠道"):
            self.select_option(loc.code_channe, doc)
        # 开启或关闭自动加好友
        # self.input_element(loc.user_add_dialog_password, password, doc)
        # 选择员工
        with allure.step("step：选择员工"):
            time.sleep(1)
            self.select_user(loc.code_select_user, doc)
        # 上传图片
        with allure.step("step：上传图片"):
            self.upload_img(loc.code_img_input, img, "上传图片")
            time.sleep(1)
        with allure.step("step：点击确定"):
            self.click_element(loc.code_create_btn, doc)
            # self.js_execute_script(loc.code_create_btn)

    def edit_code(self, codeName, img):
        doc = '员工活码列表页面_编辑活码'
        self.click_element(loc.code_edit_btn, doc)
        time.sleep(1)
        self.clear_element(loc.code_add_name)
        self.input_element(loc.code_add_name, codeName, doc)
        # 选择渠道
        time.sleep(1)
        self.select_option(loc.code_channe, '', doc)
        # 开启或关闭自动加好友
        # self.input_element(loc.user_add_dialog_password, password, doc)
        # 选择员工
        time.sleep(1)
        self.edit_user(loc.code_edit_user, doc)
        # 上传图片
        self.upload_img(loc.code_img_input, img, "上传图片")
        time.sleep(1)
        self.click_element(loc.code_create_btn, doc)

    def del_code(self):
        doc = '员工活码列表页面_删除活码'
        self.click_element(loc.code_del_btn, doc)
        time.sleep(1)
        self.click_element(loc.code_del_sure, doc)

    def get_add_result_msg(self):
        doc = '新增客户活码功能_获取新增结果信息'
        # self.wait_eleVisible(loc.user_add_dialog_msg, doc)
        return self.get_element_text(loc.code_success_msg, doc)

    def get_edit_result_msg(self):
        doc = '更新客户活码功能_获取更新结果信息'
        # self.wait_eleVisible(loc.user_add_dialog_msg, doc)
        return self.get_element_text(loc.code_success_msg, doc)

    def get_del_result_msg(self):
        doc = '删除客户活码功能_获取删除结果信息'
        # self.wait_eleVisible(loc.user_add_dialog_msg, doc)
        return self.get_element_text(loc.code_success_msg, doc)

    def get_alter(self):
        doc = '获取提醒信息'
        return self.get_element_text(loc.code_name_alter, doc)
